package com.desetalk.client.cmd;

import java.util.List;

import com.desetalk.proto.RequestProtocol.Request;

public abstract class Command {

	public final Request.Builder execute(String input) {
		
		Request.Builder result = null;
		
		if (!isHelp(input) && checkInput(input)) { // 用户输入的不为帮助且合法
			result = process(getParam(input));
		}
		
		return result;
	}
	
	public boolean isHelp(String input){
		return input.split(" ").length == 2 && input.split(" ")[1].equals("help") && printHelp();
	}

	public abstract boolean printHelp();
	
	public abstract boolean checkInput(String input);
	
	public abstract List<Object> getParam(String input);
	
	public abstract Request.Builder process(List<Object> param);
}
